package com.songhq.netty.two;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;


import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler.Sharable;//导入ChannelHandler内部注解

@Sharable
public class EchoClientHandler extends SimpleChannelInboundHandler<ByteBuf>{

	@Override
	protected void messageReceived(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
		
		System.out.println("客户端接收到了"+msg.toString(CharsetUtil.UTF_8));
	}
	//连接成功后后会触发
	@Override
	public void channelActive(ChannelHandlerContext ctx){
		ctx.writeAndFlush(Unpooled.copiedBuffer("你好，我是客户端",CharsetUtil.UTF_8));
	}
	@Override
	public void  channelRead(ChannelHandlerContext ctx, Object msg){
		
		ByteBuf f=(ByteBuf)msg;
		System.out.println("客户端clinet接收到了"+f.toString(CharsetUtil.UTF_8));
		
		
		
		
	}
}
